package com.paxcodi.rmi.chat;

import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;

public class ChatUser {
    private Queue<String> unreadMessages;
    private String name;

    ChatUser(String name) {
	this.name = name;
	unreadMessages = new ConcurrentLinkedQueue<String>(); //FIFO queue
    }

    String getName() {
	return name;
    }

    void addToUnreadMessages(String senderName, String msg){
	unreadMessages.add(senderName + ": " + msg );
	printUnreadMessages();//debug
    }

    //debug - non queue-destructive printing
    private void printUnreadMessages(){
	System.out.println("----");
	System.out.println("Unread Messages for User " + getName());
	for(String currentMsg : unreadMessages){
	    System.out.println(currentMsg);
	}
	System.out.println("----");
    }

    public String pollFromUnreadMessages() {
	return unreadMessages.poll();
    }

}
